        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>Properties class / properties Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="properties" data-type="Properties">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../properties.html">properties</a> &rsaquo; <a href="../properties/Properties.html">Properties</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
<h2><div class="icon-library"></div><a href="../properties.html">properties</a></h2><ul class="icon">
<li><a href="../properties/AddEvent.html"><div class="icon-class"></div>AddEvent</a></li>
<li><a href="../properties/BoolEvaluator.html"><div class="icon-class"></div>BoolEvaluator</a></li>
<li><div class="icon-class"></div><strong>Properties</strong></li>
<li><a href="../properties/PropertiesEvent.html"><div class="icon-class"></div>PropertiesEvent&lt;T&gt;</a></li>
<li><a href="../properties/UpdateEvent.html"><div class="icon-class"></div>UpdateEvent</a></li>
</ul>
</div>
<div class="content">
        <h2><strong>Properties</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<p>The Properties class implementing all tools to load key-values from file both by name and
path.</p>
<pre class="source">
class Properties {
 
 static final int SLASH = '\\'.charCodes[0];
 static final int SPACE = ' '.charCodes[0];
 static final int NEWLINE = '\n'.charCodes[0];
 static final int EQUAL = '='.charCodes[0];
 static final int HASH = '#'.charCodes[0];
 static final int ESCLMARK = '!'.charCodes[0];
 
 /// The content of the properties file in terms of key - value couples
 Map&lt;String,String&gt; _content;
 
 /// An internal reference to the source file.
 String _sourceFile;
 
 /// Events are enabled by default
 bool _enableEvents = true;
 
 /// Default bool evaluator instance
 BoolEvaluator _be = new BoolEvaluator();
 
 /// The property added event name
 static const String ADD_PROPERTY_EVENTNAME = 'add';
 static const String UPDATE_PROPERTY_EVENTNAME = 'update';
 
 StreamController eventController;
 
 /**
  * Create a new properties instance by naming the source file using [name].
  */
 Properties(String name){
   
   this._sourceFile = name;
   
   _init();
   
   _initFromFile();
   
 }
 
 /**
  * Create a new properties instance from file [path].
  */
 Properties.fromFile(String path){
   
   this._sourceFile = path;
   
   _init();
   
   _initFromFile();
   
 }
 
 /**
  * Create a new properties instance from the input [map].
  */
 Properties.fromMap(Map&lt;String,String&gt; map){
   
   this._content = map;
   
 }
 
 /**
  * Create a new properties instance using the input [jsonMap]
  * to load the data from.
  */
 Properties.fromJSON(String jsonMap){
   
   _init();
   
   _content = JSON.parse(jsonMap) as Map&lt;String,String&gt;;
 }

 /**
  * Initialize common internal tools such as event controllers.
  */
 _init() {
   eventController = new StreamController&lt;PropertiesEvent&gt;.broadcast();
 }
 
 void _initFromFile() =&gt; _load(_read(_sourceFile));

 /**
  * Create the file object and read its content in lines.
  */
 List&lt;List&lt;int&gt;&gt; _read(String path) {
   
   var f = _getFile(path);
   
   if(f == null || !f.existsSync())
     return null;
   
   // read file as bytes
   List&lt;int&gt; bytes = f.readAsBytesSync();
   
   // get line of bytes, managing multi-line properties
   return _manageMultiLine(_getLines(bytes));
 }
 
 /**
  * Get an array of lines of bytes out of the plain bytes.
  */
 List&lt;List&lt;int&gt;&gt; _getLines(List&lt;int&gt; bytes){
   List&lt;List&lt;int&gt;&gt; result = [];
   List&lt;int&gt; line = [];
   
   for(var i = 0; i &lt; bytes.length; i++){
     
     if(bytes[i] != Properties.NEWLINE){
       line.add(bytes[i]);
     } else {
       result.add(line);
       line = [];
     }
     
     if(i == bytes.length -1)
       result.add(line);
     
   }
   
   return result;
 }

 /**
  * Merge multi-line values into a single line value.
  */
 List&lt;List&lt;int&gt;&gt; _manageMultiLine(List&lt;List&lt;int&gt;&gt; lines) {
   var result = [];
   var app = [];
   bool isMultiLine = false;
   bool added = false;
   
   for(List&lt;int&gt; l in lines){
     
     if(isMultiLine){
       app.addAll(_replaceLastOccurrence(l, Properties.SLASH, Properties.SPACE));
       added = true;
     }
     
     if(_endsWith(l, Properties.SLASH))
       isMultiLine = true;
     else {
       isMultiLine = false;
     }
     
     
     if(!isMultiLine){
       if(!app.isEmpty){
         result.add(app);
         app = [];
       } else {
         result.add(l);
       }
     }
     
     if(isMultiLine &amp;&amp; !added){
       app.addAll(_replaceLastOccurrence(l, Properties.SLASH, Properties.SPACE));
     }
     
     added = false;
     
   }
   
   return result;
 }
 
 /**
  * Test if a [line] of bytes ends with the input [char] or not.
  */
 bool _endsWith(List&lt;int&gt; line, int char){
   return line.lastIndexOf(char) == (line.length -1);
 }

 /**
  * Replace the last occurrence of the input char [toReplace] into the input [line] of bytes
  * with the input char [replacer].
  */
 List&lt;int&gt; _replaceLastOccurrence(List&lt;int&gt; line, int toReplace, int replacer){
   List&lt;int&gt; result = [];
   bool replace = false;
   int limit = line.length;
   
   if(line.lastIndexOf(toReplace) == (line.length -1)){
     replace = true;
   }
   
   for(int i = 0; i &lt; limit; i++){
     if(replace &amp;&amp; (i == limit-1)){
       result.add(replacer);  
     } else {
       result.add(line[i]);
     }
   }
   
   return result;
 }
 

 /**
  * Load properties from lines.
  */
 _load(List&lt;List&lt;int&gt;&gt; lines) {
   if(lines == null || lines.isEmpty)
     return null;
   
   _content = new Map&lt;String,String&gt;();
   
   for(List&lt;int&gt; l in lines){
     if(_isProperty(l)){
       List&lt;List&lt;int&gt;&gt; splitted = _splitKeyValue(l);
       _content[new String.fromCharCodes(splitted[0]).trim()] = new String.fromCharCodes(splitted[1]).trim();
     }
   }
 }
 
 /**
  * Given a [line] of bytes split it into key and value.
  */
 List&lt;List&lt;int&gt;&gt; _splitKeyValue(List&lt;int&gt; line){
   
   List&lt;List&lt;int&gt;&gt; result = [];
   List&lt;int&gt; key = [];
   List&lt;int&gt; value = [];
   
   bool isKey = true;
   
   for(var i = 0; i &lt; line.length; i++){
     
     if(line[i] == Properties.EQUAL &amp;&amp; isKey){
       isKey = false;
     } else {
       if(isKey){
         key.add(line[i]);
       } else {
         value.add(line[i]);
       }
     }
   }
   
   result.add(key);
   result.add(value);
   
   return result;
 }

 /**
  * Determine if input line is a property or not.
  */
 _isProperty(List&lt;int&gt; line) {
   
   if(line.isEmpty || line == null)
     return false;
   
   if(_isComment(line))
     return false;
   
   // contains a non escaped =
   for(var i = 0; i &lt; line.length; i++){
     if(line[i] == Properties.EQUAL &amp;&amp; line[i-1] != Properties.SLASH){
       return true;
     }
   }
     
   return false;
 }
 
 /**
  * Determine if input line is a comment line.
  */
 _isComment(List&lt;int&gt; line){
   
   String lineStr = new String.fromCharCodes(line);
   
   // comment
   if(lineStr.startsWith('#'))
     return true;
   
   // comment
   if(lineStr.startsWith('!'))
     return true;
   
   return false;
 }
 
 /**
  * Get a file instance from the input string [file].
  */
 File _getFile(String file){
   
   var result = new File(file);
   
   if(result.existsSync())
     return result;
   
   result = new File.fromPath(new Path(file));
   
   if(result.existsSync())
     return result;
   
   throw new FileIOException('It\'s impossible to load properties from input file ${file}. File does not exist.');
 }
 
 /** 
  * Loads the value of a property given its [key].
  * Use [defval] to set a default value in case of missing property.
  * Use [defkey] to set a default key in case of missing property.
  */
 String get(String key, {Object defval, String defkey}) {
   if(!?key)
     return null;
   
   if(_content == null)
     return null;
   
   if(defval == null &amp;&amp; defkey == null)
     return _content[key];
   
   if(_content[key] == null){
     if(defval != null)
       return defval.toString();
     
     if(defkey != null)
       return _content[defkey];
   }
   
   return _content[key];
 }
 
 /** 
  * Loads the value of a property as a bool given its [key].
  * Boolean value evaluation can be customized using by setting 
  * a new BoolEvaluator instance.
  * Use [defval] to set a default value in case of missing property.
  * Use [defkey] to set a default key in case of missing property.
  */
 bool getBool(String key, {bool throwException:false, int defval, String defkey}) {
   var value = get(key, defval:defval, defkey:defkey);
   if(value == null)
     return null;
   
   try {
     return _be.evaluate(value);
   } on FormatException catch (e) {
     if(throwException)
       throw e;
     return null;
   }
 }
 
 /** 
  * Loads the value of a property as an integer given its [key].
  * Use [defval] to set a default value in case of missing property.
  * Use [defkey] to set a default key in case of missing property.
  */
 int getInt(String key, {bool throwException:false, int defval, String defkey}) {
   
   var value = get(key, defval:defval, defkey:defkey);
   if(value == null)
     return null;
   
   try {
     return int.parse(value);
   } on FormatException catch (e) {
     if(throwException)
       throw e;
     return null;
   }
 }
 
 /** 
  * Loads the value of a property as a double given its [key].
  * Use [defval] to set a default value in case of missing property.
  * Use [defkey] to set a default key in case of missing property.
  */
 double getDouble(String key, {bool throwException:false, double defval, String defkey}) {
   
   String value = get(key, defval:defval, defkey:defkey);
   if(value == null)
     return null;
   
   try {
     return double.parse(value);
   } on FormatException catch (e) {
     if(throwException)
       throw e;
     return null;
   }
 }
 
 /**
  * Loads a list of strings for the input [key]. List elements must be
  * comma separated.
  */
 List&lt;String&gt; getList(String key){
   String value = get(key);
   if(value == null)
     return null;
   
   return value.split(",");
 }
 
 /** Check whether the properties contains a property given its [key] */
 bool contains(String key) =&gt; key != null ? _content != null ? _content.containsKey(key) : null : null;
 
 /** Rerturns the whole set of keys */
 Iterable&lt;String&gt; get keys =&gt; _content.keys;
 
 /** Returns the whole set of values */
 Collection&lt;String&gt; get values =&gt; _content.values;
 
 /** Returns the current number of properties */
 int get size =&gt; _content.length;
 
 /**
  * Add a property to the instance having name [key] and
  * value [value]. If the property already exists its value
  * will be replaced. Returns true if the property was
  * added successfully, false otherwise.
  * 
  * If and only if a new property is added an ADD event is
  * triggered.
  */
 bool add(String key, String value, [bool overwriteExisting = true]){
   if(key == null || value == null)
     return false;
   
   if(contains(key) &amp;&amp; overwriteExisting){
     _update(key, value);
     return true;
   }
   
   
   if(!contains(key)){
     _add(key,value);
     return true;
   }
   
   return false;
 }

 /**
  * Internal add implementation, managing property storage and
  * event triggering.
  */
 _add(String key, String value) {
   _content[key] = value;
   
   if(this._enableEvents)
     eventController.add(new AddEvent(key, value));
 }

 /**
  * Internal update implementation, managing property storage and
  * event triggering.
  */
 _update(String key, String newvalue) {
   
   String oldvalue = _content[key];
   
   _content[key] = newvalue;
   
   if(this._enableEvents)
     eventController.add(new UpdateEvent(key, newvalue, oldvalue));
 }
 
 /**
  * Merge input [properties] content with the current instance's properties.
  * By defatult already existing properties will be overwritten. Anyway user
  * may decide how to manage existing thanks to the optional parameter [overwriteExisting].
  */
 void merge(Properties properties, [bool overwriteExisting = true]){
   for(String key in properties.keys){
     if(overwriteExisting || _content[key] == null){
       _content[key] = properties.get(key);
     }
   }
 }
 
 /**
  * Merge properties from the input [map] with the current instance's properties.
  * By defatult already existing properties will be overwritten. Anyway user
  * may decide how to manage existing thanks to the optional parameter [overwriteExisting].
  */
 void mergeMap(Map&lt;String,String&gt; map, [bool overwriteExisting = true]){
   for(String key in map.keys){
     if(overwriteExisting || _content[key] == null){
       _content[key] = map[key];
     }
   }
 }
 
 /**
  * Merge properties from the input [jsonMap] with the current instance's properties.
  * By defatult already existing properties will be overwritten. Anyway user
  * may decide how to manage existing thanks to the optional parameter [overwriteExisting].
  */
 void mergeJSON(String jsonMap, [bool overwriteExisting = true]){
   
   var parsed = JSON.parse(jsonMap) as Map&lt;String,String&gt;;
   
   for(String key in parsed.keys){
     if(overwriteExisting || _content[key] == null){
       _content[key] = parsed[key];
     }
   }
 }
 
 /**
  * Returns a Properties instance containg every property whos key satisifies the predicate [k] on the property key, and 
  * optionally the predicate [v] on the corresponding value. Returns null otherwise.
  */
 Properties every(bool k(String str), [bool v(String val)]) {
   
   Map&lt;String,String&gt; result = _every(k, v);
     
   if(result.isEmpty)
     return null;
   
   return new Properties.fromMap(result);
 }
 
 Map&lt;String,String&gt; _every(bool k(String str), [bool v(String val)]) {
   
   if(v == null) v = (String s) =&gt; true;
   
   var result = new Map&lt;String,String&gt;();
   for (String key in _content.keys)
     if (k(key) &amp;&amp; v(get(key))) result[key] = get(key);
     
   return result;
 }

 
 /**
  * Reloads the properties from file. Works for file sources only.
  */
 reload(){
   if(_sourceFile == null)
     return;
   
   _content.clear();
   _initFromFile();
 }
 
 /**
  * Export the content as a JSON map. If no input parameter is set, then the whole set of
  * properties will be exporte as a JSON map. If the [prefix] parameter is set,
  * then only the keys starting with [prefix] will be exported. If the [suffix] parameter is set,
  * then only the keys starting with [suffix] will be exported. If both are set, then only the
  * keys matching both will be exported.
  */
 String toJSON({String prefix, String suffix}){
   
   var toExport = _content;
   
   if(?prefix &amp;&amp; ?suffix)
     toExport = _every((key) =&gt; key.startsWith(prefix) &amp;&amp; key.endsWith(suffix));
   else if(?prefix)
     toExport = _every((key) =&gt; key.startsWith(prefix));
   else if(?suffix)
     toExport = _every((key) =&gt; key.endsWith(suffix));
   
   return JSON.stringify(toExport);
 }
 
 /**
  * Returns the whole content as a String.
  */
 String toString() =&gt; _content.toString();
 
 /**
  * Getter for [enableEvents] flag.
  */
 bool get enableEvents =&gt; this._enableEvents;
 
 /**
  * Enable / disable events triggering on this instance.
  */
 set enableEvents(bool enable) =&gt; this._enableEvents = enable;
 
 /**
  * Get the stream instance for the "property added" event.
  */
 Stream get onAdd =&gt; eventController.stream;
 
 /**
  * Get the stream instance for the "property updated" event.
  */
 Stream get onUpdate =&gt; eventController.stream;
 
 /**
  * Getter for [boolEvaluator] instance.
  */
 BoolEvaluator get boolEvaluator =&gt; this._be;
 
 /**
  * Set an [evaluator] instance.
  */
 set boolEvaluator(BoolEvaluator evaluator) =&gt; this._be = evaluator;
}
</pre>
</div>
<div>
<h3>Static Properties</h3>
<div class="field"><h4 id="ADD_PROPERTY_EVENTNAME">
<button class="show-code">Code</button>
const <a href="http://api.dartlang.org/dart_core/String.html">String</a>         <strong>ADD_PROPERTY_EVENTNAME</strong> <a class="anchor-link"
            href="#ADD_PROPERTY_EVENTNAME"
            title="Permalink to Properties.ADD_PROPERTY_EVENTNAME">#</a>
        </h4>
        <div class="doc">
<pre class="source">
ADD_PROPERTY_EVENTNAME = 'add'
</pre>
</div>
</div>
<div class="field"><h4 id="EQUAL">
<button class="show-code">Code</button>
final <a href="http://api.dartlang.org/dart_core/int.html">int</a>         <strong>EQUAL</strong> <a class="anchor-link"
            href="#EQUAL"
            title="Permalink to Properties.EQUAL">#</a>
        </h4>
        <div class="doc">
<pre class="source">
EQUAL = '='.charCodes[0]
</pre>
</div>
</div>
<div class="field"><h4 id="ESCLMARK">
<button class="show-code">Code</button>
final <a href="http://api.dartlang.org/dart_core/int.html">int</a>         <strong>ESCLMARK</strong> <a class="anchor-link"
            href="#ESCLMARK"
            title="Permalink to Properties.ESCLMARK">#</a>
        </h4>
        <div class="doc">
<pre class="source">
ESCLMARK = '!'.charCodes[0]
</pre>
</div>
</div>
<div class="field"><h4 id="HASH">
<button class="show-code">Code</button>
final <a href="http://api.dartlang.org/dart_core/int.html">int</a>         <strong>HASH</strong> <a class="anchor-link"
            href="#HASH"
            title="Permalink to Properties.HASH">#</a>
        </h4>
        <div class="doc">
<pre class="source">
HASH = '#'.charCodes[0]
</pre>
</div>
</div>
<div class="field"><h4 id="NEWLINE">
<button class="show-code">Code</button>
final <a href="http://api.dartlang.org/dart_core/int.html">int</a>         <strong>NEWLINE</strong> <a class="anchor-link"
            href="#NEWLINE"
            title="Permalink to Properties.NEWLINE">#</a>
        </h4>
        <div class="doc">
<pre class="source">
NEWLINE = '\n'.charCodes[0]
</pre>
</div>
</div>
<div class="field"><h4 id="SLASH">
<button class="show-code">Code</button>
final <a href="http://api.dartlang.org/dart_core/int.html">int</a>         <strong>SLASH</strong> <a class="anchor-link"
            href="#SLASH"
            title="Permalink to Properties.SLASH">#</a>
        </h4>
        <div class="doc">
<pre class="source">
SLASH = '\\'.charCodes[0]
</pre>
</div>
</div>
<div class="field"><h4 id="SPACE">
<button class="show-code">Code</button>
final <a href="http://api.dartlang.org/dart_core/int.html">int</a>         <strong>SPACE</strong> <a class="anchor-link"
            href="#SPACE"
            title="Permalink to Properties.SPACE">#</a>
        </h4>
        <div class="doc">
<pre class="source">
SPACE = ' '.charCodes[0]
</pre>
</div>
</div>
<div class="field"><h4 id="UPDATE_PROPERTY_EVENTNAME">
<button class="show-code">Code</button>
const <a href="http://api.dartlang.org/dart_core/String.html">String</a>         <strong>UPDATE_PROPERTY_EVENTNAME</strong> <a class="anchor-link"
            href="#UPDATE_PROPERTY_EVENTNAME"
            title="Permalink to Properties.UPDATE_PROPERTY_EVENTNAME">#</a>
        </h4>
        <div class="doc">
<pre class="source">
UPDATE_PROPERTY_EVENTNAME = 'update'
</pre>
</div>
</div>
</div>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="Properties">
<button class="show-code">Code</button>
new <strong>Properties</strong>(<a href="http://api.dartlang.org/dart_core/String.html">String</a> name) <a class="anchor-link" href="#Properties"
              title="Permalink to Properties.Properties">#</a></h4>
<div class="doc">
<p>Create a new properties instance by naming the source file using 
<span class="param">name</span>.</p>
<pre class="source">
Properties(String name){
 
 this._sourceFile = name;
 
 _init();
 
 _initFromFile();
 
}
</pre>
</div>
</div>
<div class="method"><h4 id="Properties.fromFile">
<button class="show-code">Code</button>
new <strong>Properties.fromFile</strong>(<a href="http://api.dartlang.org/dart_core/String.html">String</a> path) <a class="anchor-link" href="#Properties.fromFile"
              title="Permalink to Properties.Properties.fromFile">#</a></h4>
<div class="doc">
<p>Create a new properties instance from file 
<span class="param">path</span>.</p>
<pre class="source">
Properties.fromFile(String path){
 
 this._sourceFile = path;
 
 _init();
 
 _initFromFile();
 
}
</pre>
</div>
</div>
<div class="method"><h4 id="Properties.fromJSON">
<button class="show-code">Code</button>
new <strong>Properties.fromJSON</strong>(<a href="http://api.dartlang.org/dart_core/String.html">String</a> jsonMap) <a class="anchor-link" href="#Properties.fromJSON"
              title="Permalink to Properties.Properties.fromJSON">#</a></h4>
<div class="doc">
<p>Create a new properties instance using the input 
<span class="param">jsonMap</span>
to load the data from.</p>
<pre class="source">
Properties.fromJSON(String jsonMap){
 
 _init();
 
 _content = JSON.parse(jsonMap) as Map&lt;String,String&gt;;
}
</pre>
</div>
</div>
<div class="method"><h4 id="Properties.fromMap">
<button class="show-code">Code</button>
new <strong>Properties.fromMap</strong>(<a href="http://api.dartlang.org/dart_core/Map.html">Map</a>&lt;<a href="http://api.dartlang.org/dart_core/String.html">String</a>, <a href="http://api.dartlang.org/dart_core/String.html">String</a>&gt; map) <a class="anchor-link" href="#Properties.fromMap"
              title="Permalink to Properties.Properties.fromMap">#</a></h4>
<div class="doc">
<p>Create a new properties instance from the input 
<span class="param">map</span>.</p>
<pre class="source">
Properties.fromMap(Map&lt;String,String&gt; map){
 
 this._content = map;
 
}
</pre>
</div>
</div>
</div>
<div>
<h3>Properties</h3>
<div class="method"><h4 id="boolEvaluator">
<button class="show-code">Code</button>
<a href="../properties/BoolEvaluator.html">BoolEvaluator</a> <strong>get boolEvaluator</strong> <a class="anchor-link" href="#boolEvaluator"
              title="Permalink to Properties.get boolEvaluator">#</a></h4>
<div class="doc">
<p>Getter for <a class="crossref" href="../properties/Properties.html#boolEvaluator">boolEvaluator</a> instance.</p>
<pre class="source">
BoolEvaluator get boolEvaluator =&gt; this._be;
</pre>
</div>
</div>
<div class="method"><h4 id="boolEvaluator=">
<button class="show-code">Code</button>
<strong>set boolEvaluator</strong>(<a href="../properties/BoolEvaluator.html">BoolEvaluator</a> evaluator) <a class="anchor-link" href="#boolEvaluator="
              title="Permalink to Properties.set boolEvaluator">#</a></h4>
<div class="doc">
<p>Set an 
<span class="param">evaluator</span> instance.</p>
<pre class="source">
set boolEvaluator(BoolEvaluator evaluator) =&gt; this._be = evaluator;
</pre>
</div>
</div>
<div class="method"><h4 id="enableEvents">
<button class="show-code">Code</button>
<a href="http://api.dartlang.org/dart_core/bool.html">bool</a> <strong>get enableEvents</strong> <a class="anchor-link" href="#enableEvents"
              title="Permalink to Properties.get enableEvents">#</a></h4>
<div class="doc">
<p>Getter for <a class="crossref" href="../properties/Properties.html#enableEvents">enableEvents</a> flag.</p>
<pre class="source">
bool get enableEvents =&gt; this._enableEvents;
</pre>
</div>
</div>
<div class="method"><h4 id="enableEvents=">
<button class="show-code">Code</button>
<strong>set enableEvents</strong>(<a href="http://api.dartlang.org/dart_core/bool.html">bool</a> enable) <a class="anchor-link" href="#enableEvents="
              title="Permalink to Properties.set enableEvents">#</a></h4>
<div class="doc">
<p>Enable / disable events triggering on this instance.</p>
<pre class="source">
set enableEvents(bool enable) =&gt; this._enableEvents = enable;
</pre>
</div>
</div>
<div class="field"><h4 id="eventController">
<button class="show-code">Code</button>
<a href="http://api.dartlang.org/dart_async/StreamController.html">StreamController</a>         <strong>eventController</strong> <a class="anchor-link"
            href="#eventController"
            title="Permalink to Properties.eventController">#</a>
        </h4>
        <div class="doc">
<pre class="source">
eventController
</pre>
</div>
</div>
<div class="field"><h4 id="keys">
<button class="show-code">Code</button>
final <a href="http://api.dartlang.org/dart_core/Iterable.html">Iterable</a>&lt;<a href="http://api.dartlang.org/dart_core/String.html">String</a>&gt;         <strong>keys</strong> <a class="anchor-link"
            href="#keys"
            title="Permalink to Properties.keys">#</a>
        </h4>
        <div class="doc">
<p>Rerturns the whole set of keys </p>
<pre class="source">
Iterable&lt;String&gt; get keys =&gt; _content.keys;
</pre>
</div>
</div>
<div class="field"><h4 id="onAdd">
<button class="show-code">Code</button>
final <a href="http://api.dartlang.org/dart_async/Stream.html">Stream</a>         <strong>onAdd</strong> <a class="anchor-link"
            href="#onAdd"
            title="Permalink to Properties.onAdd">#</a>
        </h4>
        <div class="doc">
<p>Get the stream instance for the "property added" event.</p>
<pre class="source">
Stream get onAdd =&gt; eventController.stream;
</pre>
</div>
</div>
<div class="field"><h4 id="onUpdate">
<button class="show-code">Code</button>
final <a href="http://api.dartlang.org/dart_async/Stream.html">Stream</a>         <strong>onUpdate</strong> <a class="anchor-link"
            href="#onUpdate"
            title="Permalink to Properties.onUpdate">#</a>
        </h4>
        <div class="doc">
<p>Get the stream instance for the "property updated" event.</p>
<pre class="source">
Stream get onUpdate =&gt; eventController.stream;
</pre>
</div>
</div>
<div class="field"><h4 id="size">
<button class="show-code">Code</button>
final <a href="http://api.dartlang.org/dart_core/int.html">int</a>         <strong>size</strong> <a class="anchor-link"
            href="#size"
            title="Permalink to Properties.size">#</a>
        </h4>
        <div class="doc">
<p>Returns the current number of properties </p>
<pre class="source">
int get size =&gt; _content.length;
</pre>
</div>
</div>
<div class="field"><h4 id="values">
<button class="show-code">Code</button>
final <a href="http://api.dartlang.org/dart_core/Collection.html">Collection</a>&lt;<a href="http://api.dartlang.org/dart_core/String.html">String</a>&gt;         <strong>values</strong> <a class="anchor-link"
            href="#values"
            title="Permalink to Properties.values">#</a>
        </h4>
        <div class="doc">
<p>Returns the whole set of values </p>
<pre class="source">
Collection&lt;String&gt; get values =&gt; _content.values;
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method"><h4 id="add">
<button class="show-code">Code</button>
<a href="http://api.dartlang.org/dart_core/bool.html">bool</a> <strong>add</strong>(<a href="http://api.dartlang.org/dart_core/String.html">String</a> key, <a href="http://api.dartlang.org/dart_core/String.html">String</a> value, [<a href="http://api.dartlang.org/dart_core/bool.html">bool</a> overwriteExisting = true]) <a class="anchor-link" href="#add"
              title="Permalink to Properties.add">#</a></h4>
<div class="doc">
<p>Add a property to the instance having name 
<span class="param">key</span> and
value 
<span class="param">value</span>. If the property already exists its value
will be replaced. Returns true if the property was
added successfully, false otherwise.</p>
<p>If and only if a new property is added an ADD event is
triggered.</p>
<pre class="source">
bool add(String key, String value, [bool overwriteExisting = true]){
 if(key == null || value == null)
   return false;
 
 if(contains(key) &amp;&amp; overwriteExisting){
   _update(key, value);
   return true;
 }
 
 
 if(!contains(key)){
   _add(key,value);
   return true;
 }
 
 return false;
}
</pre>
</div>
</div>
<div class="method"><h4 id="contains">
<button class="show-code">Code</button>
<a href="http://api.dartlang.org/dart_core/bool.html">bool</a> <strong>contains</strong>(<a href="http://api.dartlang.org/dart_core/String.html">String</a> key) <a class="anchor-link" href="#contains"
              title="Permalink to Properties.contains">#</a></h4>
<div class="doc">
<p>Check whether the properties contains a property given its 
<span class="param">key</span> </p>
<pre class="source">
bool contains(String key) =&gt; key != null ? _content != null ? _content.containsKey(key) : null : null;
</pre>
</div>
</div>
<div class="method"><h4 id="every">
<button class="show-code">Code</button>
<a href="../properties/Properties.html">Properties</a> <strong>every</strong>(<a href="http://api.dartlang.org/dart_core/bool.html">bool</a> k(<a href="http://api.dartlang.org/dart_core/String.html">String</a> str), [<a href="http://api.dartlang.org/dart_core/bool.html">bool</a> v(<a href="http://api.dartlang.org/dart_core/String.html">String</a> val)]) <a class="anchor-link" href="#every"
              title="Permalink to Properties.every">#</a></h4>
<div class="doc">
<p>Returns a Properties instance containg every property whos key satisifies the predicate 
<span class="param">k</span> on the property key, and 
optionally the predicate 
<span class="param">v</span> on the corresponding value. Returns null otherwise.</p>
<pre class="source">
Properties every(bool k(String str), [bool v(String val)]) {
 
 Map&lt;String,String&gt; result = _every(k, v);
   
 if(result.isEmpty)
   return null;
 
 return new Properties.fromMap(result);
}
</pre>
</div>
</div>
<div class="method"><h4 id="get">
<button class="show-code">Code</button>
<a href="http://api.dartlang.org/dart_core/String.html">String</a> <strong>get</strong>(<a href="http://api.dartlang.org/dart_core/String.html">String</a> key, {<a href="http://api.dartlang.org/dart_core/Object.html">Object</a> defval, <a href="http://api.dartlang.org/dart_core/String.html">String</a> defkey}) <a class="anchor-link" href="#get"
              title="Permalink to Properties.get">#</a></h4>
<div class="doc">
<p>Loads the value of a property given its 
<span class="param">key</span>.
Use 
<span class="param">defval</span> to set a default value in case of missing property.
Use 
<span class="param">defkey</span> to set a default key in case of missing property.</p>
<pre class="source">
String get(String key, {Object defval, String defkey}) {
 if(!?key)
   return null;
 
 if(_content == null)
   return null;
 
 if(defval == null &amp;&amp; defkey == null)
   return _content[key];
 
 if(_content[key] == null){
   if(defval != null)
     return defval.toString();
   
   if(defkey != null)
     return _content[defkey];
 }
 
 return _content[key];
}
</pre>
</div>
</div>
<div class="method"><h4 id="getBool">
<button class="show-code">Code</button>
<a href="http://api.dartlang.org/dart_core/bool.html">bool</a> <strong>getBool</strong>(<a href="http://api.dartlang.org/dart_core/String.html">String</a> key, {<a href="http://api.dartlang.org/dart_core/bool.html">bool</a> throwException: false, <a href="http://api.dartlang.org/dart_core/int.html">int</a> defval, <a href="http://api.dartlang.org/dart_core/String.html">String</a> defkey}) <a class="anchor-link" href="#getBool"
              title="Permalink to Properties.getBool">#</a></h4>
<div class="doc">
<p>Loads the value of a property as a bool given its 
<span class="param">key</span>.
Boolean value evaluation can be customized using by setting 
a new BoolEvaluator instance.
Use 
<span class="param">defval</span> to set a default value in case of missing property.
Use 
<span class="param">defkey</span> to set a default key in case of missing property.</p>
<pre class="source">
bool getBool(String key, {bool throwException:false, int defval, String defkey}) {
 var value = get(key, defval:defval, defkey:defkey);
 if(value == null)
   return null;
 
 try {
   return _be.evaluate(value);
 } on FormatException catch (e) {
   if(throwException)
     throw e;
   return null;
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="getDouble">
<button class="show-code">Code</button>
<a href="http://api.dartlang.org/dart_core/double.html">double</a> <strong>getDouble</strong>(<a href="http://api.dartlang.org/dart_core/String.html">String</a> key, {<a href="http://api.dartlang.org/dart_core/bool.html">bool</a> throwException: false, <a href="http://api.dartlang.org/dart_core/double.html">double</a> defval, <a href="http://api.dartlang.org/dart_core/String.html">String</a> defkey}) <a class="anchor-link" href="#getDouble"
              title="Permalink to Properties.getDouble">#</a></h4>
<div class="doc">
<p>Loads the value of a property as a double given its 
<span class="param">key</span>.
Use 
<span class="param">defval</span> to set a default value in case of missing property.
Use 
<span class="param">defkey</span> to set a default key in case of missing property.</p>
<pre class="source">
double getDouble(String key, {bool throwException:false, double defval, String defkey}) {
 
 String value = get(key, defval:defval, defkey:defkey);
 if(value == null)
   return null;
 
 try {
   return double.parse(value);
 } on FormatException catch (e) {
   if(throwException)
     throw e;
   return null;
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="getInt">
<button class="show-code">Code</button>
<a href="http://api.dartlang.org/dart_core/int.html">int</a> <strong>getInt</strong>(<a href="http://api.dartlang.org/dart_core/String.html">String</a> key, {<a href="http://api.dartlang.org/dart_core/bool.html">bool</a> throwException: false, <a href="http://api.dartlang.org/dart_core/int.html">int</a> defval, <a href="http://api.dartlang.org/dart_core/String.html">String</a> defkey}) <a class="anchor-link" href="#getInt"
              title="Permalink to Properties.getInt">#</a></h4>
<div class="doc">
<p>Loads the value of a property as an integer given its 
<span class="param">key</span>.
Use 
<span class="param">defval</span> to set a default value in case of missing property.
Use 
<span class="param">defkey</span> to set a default key in case of missing property.</p>
<pre class="source">
int getInt(String key, {bool throwException:false, int defval, String defkey}) {
 
 var value = get(key, defval:defval, defkey:defkey);
 if(value == null)
   return null;
 
 try {
   return int.parse(value);
 } on FormatException catch (e) {
   if(throwException)
     throw e;
   return null;
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="getList">
<button class="show-code">Code</button>
<a href="http://api.dartlang.org/dart_core/List.html">List</a>&lt;<a href="http://api.dartlang.org/dart_core/String.html">String</a>&gt; <strong>getList</strong>(<a href="http://api.dartlang.org/dart_core/String.html">String</a> key) <a class="anchor-link" href="#getList"
              title="Permalink to Properties.getList">#</a></h4>
<div class="doc">
<p>Loads a list of strings for the input 
<span class="param">key</span>. List elements must be
comma separated.</p>
<pre class="source">
List&lt;String&gt; getList(String key){
 String value = get(key);
 if(value == null)
   return null;
 
 return value.split(",");
}
</pre>
</div>
</div>
<div class="method"><h4 id="merge">
<button class="show-code">Code</button>
void <strong>merge</strong>(<a href="../properties/Properties.html">Properties</a> properties, [<a href="http://api.dartlang.org/dart_core/bool.html">bool</a> overwriteExisting = true]) <a class="anchor-link" href="#merge"
              title="Permalink to Properties.merge">#</a></h4>
<div class="doc">
<p>Merge input 
<span class="param">properties</span> content with the current instance's properties.
By defatult already existing properties will be overwritten. Anyway user
may decide how to manage existing thanks to the optional parameter 
<span class="param">overwriteExisting</span>.</p>
<pre class="source">
void merge(Properties properties, [bool overwriteExisting = true]){
 for(String key in properties.keys){
   if(overwriteExisting || _content[key] == null){
     _content[key] = properties.get(key);
   }
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="mergeJSON">
<button class="show-code">Code</button>
void <strong>mergeJSON</strong>(<a href="http://api.dartlang.org/dart_core/String.html">String</a> jsonMap, [<a href="http://api.dartlang.org/dart_core/bool.html">bool</a> overwriteExisting = true]) <a class="anchor-link" href="#mergeJSON"
              title="Permalink to Properties.mergeJSON">#</a></h4>
<div class="doc">
<p>Merge properties from the input 
<span class="param">jsonMap</span> with the current instance's properties.
By defatult already existing properties will be overwritten. Anyway user
may decide how to manage existing thanks to the optional parameter 
<span class="param">overwriteExisting</span>.</p>
<pre class="source">
void mergeJSON(String jsonMap, [bool overwriteExisting = true]){
 
 var parsed = JSON.parse(jsonMap) as Map&lt;String,String&gt;;
 
 for(String key in parsed.keys){
   if(overwriteExisting || _content[key] == null){
     _content[key] = parsed[key];
   }
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="mergeMap">
<button class="show-code">Code</button>
void <strong>mergeMap</strong>(<a href="http://api.dartlang.org/dart_core/Map.html">Map</a>&lt;<a href="http://api.dartlang.org/dart_core/String.html">String</a>, <a href="http://api.dartlang.org/dart_core/String.html">String</a>&gt; map, [<a href="http://api.dartlang.org/dart_core/bool.html">bool</a> overwriteExisting = true]) <a class="anchor-link" href="#mergeMap"
              title="Permalink to Properties.mergeMap">#</a></h4>
<div class="doc">
<p>Merge properties from the input 
<span class="param">map</span> with the current instance's properties.
By defatult already existing properties will be overwritten. Anyway user
may decide how to manage existing thanks to the optional parameter 
<span class="param">overwriteExisting</span>.</p>
<pre class="source">
void mergeMap(Map&lt;String,String&gt; map, [bool overwriteExisting = true]){
 for(String key in map.keys){
   if(overwriteExisting || _content[key] == null){
     _content[key] = map[key];
   }
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="reload">
<button class="show-code">Code</button>
<strong>reload</strong>() <a class="anchor-link" href="#reload"
              title="Permalink to Properties.reload">#</a></h4>
<div class="doc">
<p>Reloads the properties from file. Works for file sources only.</p>
<pre class="source">
reload(){
 if(_sourceFile == null)
   return;
 
 _content.clear();
 _initFromFile();
}
</pre>
</div>
</div>
<div class="method"><h4 id="toJSON">
<button class="show-code">Code</button>
<a href="http://api.dartlang.org/dart_core/String.html">String</a> <strong>toJSON</strong>({<a href="http://api.dartlang.org/dart_core/String.html">String</a> prefix, <a href="http://api.dartlang.org/dart_core/String.html">String</a> suffix}) <a class="anchor-link" href="#toJSON"
              title="Permalink to Properties.toJSON">#</a></h4>
<div class="doc">
<p>Export the content as a JSON map. If no input parameter is set, then the whole set of
properties will be exporte as a JSON map. If the 
<span class="param">prefix</span> parameter is set,
then only the keys starting with 
<span class="param">prefix</span> will be exported. If the 
<span class="param">suffix</span> parameter is set,
then only the keys starting with 
<span class="param">suffix</span> will be exported. If both are set, then only the
keys matching both will be exported.</p>
<pre class="source">
String toJSON({String prefix, String suffix}){
 
 var toExport = _content;
 
 if(?prefix &amp;&amp; ?suffix)
   toExport = _every((key) =&gt; key.startsWith(prefix) &amp;&amp; key.endsWith(suffix));
 else if(?prefix)
   toExport = _every((key) =&gt; key.startsWith(prefix));
 else if(?suffix)
   toExport = _every((key) =&gt; key.endsWith(suffix));
 
 return JSON.stringify(toExport);
}
</pre>
</div>
</div>
<div class="method"><h4 id="toString">
<button class="show-code">Code</button>
<a href="http://api.dartlang.org/dart_core/String.html">String</a> <strong>toString</strong>() <a class="anchor-link" href="#toString"
              title="Permalink to Properties.toString">#</a></h4>
<div class="doc">
<p>Returns the whole content as a String.</p>
<pre class="source">
String toString() =&gt; _content.toString();
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        <div class="footer">
          <div>This page was generated at 2013-03-16 17:53:06.975</div>
        </div>
        <script async src="../client-static.js"></script>
        </body></html>
        
